<?php

namespace app\backend\controller;
use app\backend\service\TaskService;

class Task extends Backend
{
    /**
     * 任务列表
     * @param TaskService $service
     * @return string|\think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function index(TaskService $service)
    {
        if ($this->request->isAjax()) {
            return $this->success($service->lists($this->request->param()));
        }
        return $this->fetch('', $service->labelData());
    }

    /**
     * 添加任务
     * @param TaskService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     */
    public function add(TaskService $service)
    {
        if ($this->request->isAjax()) {
            return $this->success($service->add($this->request->param()));
        }
        return $this->fetch('', $service->labelData());
    }

    /**
     * 修改任务
     * @param TaskService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     */
    public function edit(TaskService $service)
    {
        if ($this->request->isAjax()) {
            return $this->success($service->edit($this->request->param()));
        }
        $fetchData = $service->labelData();
        $fetchData['info'] = $service->detail($this->request->param('id'));
        return $this->fetch('', $fetchData);
    }

    /**
     *  任务详情
     * @param TaskService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     */
    public function detail(TaskService $service)
    {
        $fetchData = $service->labelData();
        $fetchData['info'] = $service->detail($this->request->param('id'));
        return $this->fetch('', $fetchData);
    }
}